<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>01绑定样式class</title>
  <script src="../js/vue.js"></script>
  <style>
    .basic {
      width: 400px;
      height: 100px;
      border: 1px solid black;
    }
    .happy {
      border: 4px solid red;
      background-color: rgba(255, 255, 0, 0.644);
      background: linear-gradient(30deg, yellow, pink, orange, yellow);
    }
    .sad {
      border: 4px dashed rgb(2, 197, 2);
      background-color: gray;
    }
    .noraml {
      background-color: skyblue;
    }
    .demo1 {
      background-color: yellowgreen;
    }
    .demo2 {
      font-size: 30px;
      text-shadow: 2px 2px 10px red;
    }
    .demo3 {
      border-radius: 20px;
    }
  </style>
</head>
<body>
  <div id="app">
    <!-- 1 字符串形式：样式的类名不确定，需要动态指定 -->
    <div class="basic" :class="mood" @click.prevent="handleClick">{{title}}</div>

    <!-- 2 数组形式：样式类名不确定，个数也不确定 -->
    <div class="basic" :class="['demo1', 'demo2', 'demo3']">{{title}}</div>
    <!-- 在data中定义arr，后期可以通过操作数组来改变样式 -->
    <div class="basic" :class="arr">{{title}}</div>

    <!-- 3 对象形式：样式类名确定，个数也确定，但要动态决定用不用 -->
    <div class="basic" :class="{demo1: a, demo2: b, demo3: c}">{{title}}</div>
    <div class="basic" :class="obj">{{title}}</div>
  </div>
  <script>
    new Vue({
      el: '#app',
      data() {
        return {
          title: '绑定样式class',
          mood: 'normal',
          arr: ['demo1', 'demo2', 'demo3'],
          a: true,
          b: true,
          c: true,
          obj: {
            demo1: true,
            demo2: true,
            demo3: true
          }
        }
      },
      methods: {
        handleClick() {
          const arr = ['happy', 'sad', 'normal']
          const index = Math.floor(Math.random(0, 3) * 3)
          this.mood = arr[index]
        }
      }
    })
  </script>
</body>
</html>